package com.ruoyi.web.controller.zc;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zc.domain.ZcGrade;
import com.ruoyi.zc.service.IZcGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author xuwendi
 * @date 2023-03-19
 */
@RestController
@RequestMapping("/zc/grade")
public class ZcGradeController extends BaseController
{
    @Autowired
    private IZcGradeService zcGradeService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('zc:grade:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZcGrade zcGrade)
    {
        startPage();
        List<ZcGrade> list = zcGradeService.selectZcGradeList(zcGrade);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('zc:grade:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZcGrade zcGrade)
    {
        List<ZcGrade> list = zcGradeService.selectZcGradeList(zcGrade);
        ExcelUtil<ZcGrade> util = new ExcelUtil<ZcGrade>(ZcGrade.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
//    @PreAuthorize("@ss.hasPermi('zc:grade:query')")
    @GetMapping(value = "/{gradeId}")
    public AjaxResult getInfo(@PathVariable("gradeId") Long gradeId)
    {
        return success(zcGradeService.selectZcGradeByGradeId(gradeId));
    }

    /**
     * 新增【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('zc:grade:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZcGrade zcGrade)
    {
        if (zcGradeService.insertZcGrade(zcGrade)==1) {
            logger.debug("=======>grade add success");
            return success(zcGradeService.getNewGrade());
        } else{
            return error();
        }
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('zc:grade:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZcGrade zcGrade)
    {
        return toAjax(zcGradeService.updateZcGrade(zcGrade));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('zc:grade:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gradeIds}")
    public AjaxResult remove(@PathVariable Long[] gradeIds)
    {
        return toAjax(zcGradeService.deleteZcGradeByGradeIds(gradeIds));
    }

}
